using System;
using System.IO;

public sealed class Program {
   public static void Main() {
      FileStream fs = new FileStream("DataFile.dat", FileMode.Create);
      StreamWriter sw = new StreamWriter(fs);
      sw.Write("Hi there");

      // The following call to Close is what you should do.
      sw.Close();
      // NOTE: StreamWriter.Close closes the FileStream. 
      // The FileStream doesn't have to be explicitly closed.
   }
}